package notes.java.java8.demo.newtime;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;

/** 时间/日期*/
public class D2_LocalDateTime {

	public static void main(String[] args) {
		// 当前日期
		LocalDate ld = LocalDate.now();
		System.out.println(ld);
		System.out.println(ld.getYear() + "-" + ld.getMonthValue() + "-" + ld.getDayOfMonth());
		
		
		LocalTime lt = LocalTime.now();
		System.out.println(lt);
		
		LocalDateTime ldt = LocalDateTime.now();
		System.out.println(ldt);
		
		// 格式化
		String time = ldt.format(DateTimeFormatter.ofPattern("yyyy/MM/dd HH:mm:ss"));
		System.out.println(time);
		
		// 增加20分钟
		LocalDateTime ldt2 = ldt.plus(20, ChronoUnit.MINUTES);
		System.out.println("增加20分钟：" + ldt2);
		
		// 两时间比较
		boolean f = ldt2.isAfter(ldt);
		System.out.println("在之后吗？"+ f);
		
		// 自定义时间
		LocalDateTime ldt3 = LocalDateTime.of(2008, 8, 18, 18, 28, 58);
		System.out.println(ldt3);
		
		// 自定义时间
		LocalDateTime ldt4 = LocalDateTime.now().withHour(0).withMinute(0).withSecond(0);
		System.out.println(ldt4);
	}
}
